package Domain;

import java.util.ArrayList;
import java.util.List;



/**
 * Holds a list of books from the database. The {@link BookList}
 * contains a list of {@link Book} objects.
 * 
 * @author Daniel Fagerberg
 * 
 */
public class BookList {
	private List<Book> books;

	/**
	 * Creates an empty {@link BookList} object.
	 */
	public BookList() {
		books = new ArrayList<Book>();
	}
	/**
	 * Creates an array with the names of all products in this list. The order
	 * of the products is the internal order of the {@link ProductList}, which
	 * is based on the order the products were added.
	 * 
	 * @return the array with the names of all products of this
	 *         {@link ProductList}.
	 */
	public String[] getNames() {
		String[] BookNames = new String[books.size()];
		for (int i = 0; i < books.size(); i++) {
			BookNames[i] = books.get(i).getTitle();
		}
		return BookNames;

	}

	/**
	 * Returns the {@link Product} object at given index in the listing of this
	 * ProductList.
	 * 
	 * @param index
	 *            the position of the requested {@link Product} object
	 * @return the requested {@link Product} object
	 */
	public Book getBook(int index) {
		return books.get(index);
	}

	public void setBook(int index, Book b) {
		books.set(index, b);
	}

	/**
	 * Adds a new {@link Product} object at the end of this {@link ProductList}
	 * object listing.
	 * 
	 * @param product
	 */
	public void addBook(Book book) {
		books.add(book);
	}

	public void addAllBooks(List<Book> products) {
		this.books.addAll(books);
	}
	
	/**
	 * Returns all products of this {@link ProductList}.
	 * 
	 * @return a list of all products
	 */
	public List<Book> getBooks() {
		return new ArrayList<Book>(books);
	}

	public int getIndexOfBook(Book book) {
		return books.indexOf(book);
	}
}